package com.lagou.homework.stage02.module01.Task01.app;

import com.lagou.homework.stage02.module01.Task01.entity.Phone;
import com.lagou.homework.stage02.module01.Task01.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class PhoneTest {
    public static void main(String[] args) {
        try {
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

            System.out.println("查询价格高于2000元，生产日期是2019年之前的所有手机");
            String sql01 = "select * from phone where price > ? and prodate < ?";
            Object[] parm = {2000,"2019-0-0"};
            List<Phone> list01=qr.query(sql01, new BeanListHandler<Phone>(Phone.class), parm);
            for(Phone phone : list01){
                System.out.println(phone);
            }

            System.out.println("查询所有颜色是白色的手机信息");
            String sql02 = "select * from phone where color = '白色'";
            List<Phone> list02=qr.query(sql02, new BeanListHandler<Phone>(Phone.class));
            for(Phone phone : list02){
                System.out.println(phone);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
